--
-- Author: shunguo.chen
-- Date: 2016-12-29 14:22:24
--

local CrashReportAPI = {}

local javaclassName = "com/repong/framework/CrashReportAPI"
local ocClassName = "CrashReportAPI"

function CrashReportAPI.reportException(message, tracemsg)
	tracemsg = tracemsg or debug.traceback("", 2)
	if device.platform=="android" then
		local args = {6, "", message, tracemsg}
		local sigs = "(ILjava/lang/String;Ljava/lang/String;[B)V"
		local ok = luaj.callStaticMethod(javaclassName, "reportException", args, sigs)
		if not ok then
			print("CrashReportAPI reportException fail")
		end
	elseif device.platform=="ios" then
		local params = {category=6, name="", reason=message, trace=tracemsg}
		local ok,_ = luaoc.callStaticMethod(ocClassName, "reportException", params)
		if not ok then
			print("CrashReportAPI regist fail:",ret)
		end
	end
end

function CrashReportAPI.setUserId(uid)
	if device.platform=="android" then
		local args = {uid}
		local sigs = "(Ljava/lang/String;)V"
		local ok = luaj.callStaticMethod(javaclassName, "setUserId", args, sigs)
		if not ok then
			print("CrashReportAPI setUserId fail")
		end
	elseif device.platform=="ios" then
		local ok,_ = luaoc.callStaticMethod(ocClassName, "setUserId", {uid=uid})
		if not ok then
			print("CrashReportAPI setUserId fail:",ret)
		end
	end
end

function CrashReportAPI.addUserValue(key, value)
	if device.platform=="android" then
		local args = {key, value}
		local sigs = "(Ljava/lang/String;Ljava/lang/String;)V"
		local ok = luaj.callStaticMethod(javaclassName, "putUserData", args, sigs)
		if not ok then
			print("CrashReportAPI addUserValue fail")
		end
	elseif device.platform=="ios" then
		local ok,_ = luaoc.callStaticMethod(ocClassName, "addUserValue", {key=key,value=value})
		if not ok then
			print("CrashReportAPI addUserValue fail:",ret)
		end
	end
end

function CrashReportAPI.removeUserValue(key)
	if device.platform=="android" then
		local args = {key}
		local sigs = "(Ljava/lang/String;)V"
		local ok = luaj.callStaticMethod(javaclassName, "removeUserData", args, sigs)
		if not ok then
			print("CrashReportAPI removeUserValue fail")
		end
	elseif device.platform=="ios" then
		local ok,_ = luaoc.callStaticMethod(ocClassName, "removeUserValue", {key=key})
		if not ok then
			print("CrashReportAPI removeUserValue fail:",ret)
		end
	end
end

function CrashReportAPI.setTag(tag)
	if device.platform=="android" then
		local args = {tag}
		local sigs = "(I)V"
		local ok = luaj.callStaticMethod(javaclassName, "setUserSceneTag", args, sigs)
		if not ok then
			print("CrashReportAPI setTag fail")
		end
	elseif device.platform=="ios" then
		local ok,_ = luaoc.callStaticMethod(ocClassName, "setUserSceneTag", {tag=tag})
		if not ok then
			print("CrashReportAPI setTag fail:",ret)
		end
	end
end

function CrashReportAPI.testNativeCrash()
	if device.platform=="android" then
		local args = {}
		local sigs = "()V"
		local ok = luaj.callStaticMethod(javaclassName, "testNativeCrash", args, sigs)
		if not ok then
			print("CrashReportAPI testNativeCrash fail")
		end
	elseif device.platform=="ios" then

	end
end

function CrashReportAPI.testJavaCrash()
	if device.platform=="android" then
		local args = {}
		local sigs = "()V"
		local ok = luaj.callStaticMethod(javaclassName, "testJavaCrash", args, sigs)
		if not ok then
			print("CrashReportAPI testJavaCrash fail")
		end
	elseif device.platform=="ios" then

	end
end

function CrashReportAPI.log(level, tag, log)

end

return CrashReportAPI